services:
  {{ service_name }}:
    image: docker.io/gitlab/gitlab-ce:18.5.2-ce.0
    container_name: {{ container_name }}
    shm_size: '256m'
{% if traefik_enabled %}
    networks:
      - {{ traefik_network }}
{% endif %}
    volumes:
      - ./config/gitlab.rb:/etc/gitlab/gitlab.rb:ro
      - gitlab-config:/etc/gitlab
      - gitlab-logs:/var/log/gitlab
      - gitlab-data:/var/opt/gitlab
{% if ports_enabled %}
    ports:
      - "{{ ports_http }}:80"
      - "{{ ports_ssh }}:22"
      {% if registry_enabled %}
      - "{{ ports_registry }}:5678"
      {% endif %}
{% else %}
    ports:
      - "{{ ports_ssh }}:22"
{% endif %}
{% if traefik_enabled %}
    labels:
      - traefik.enable=true
      - traefik.docker.network={{ traefik_network }}
      - traefik.http.services.{{ container_name }}.loadbalancer.server.port=80
      - traefik.http.services.{{ container_name }}.loadbalancer.server.scheme=http
      - traefik.http.routers.{{ container_name }}-http.service={{ container_name }}
      - traefik.http.routers.{{ container_name }}-http.rule=Host(`{{ traefik_host }}`)
      - traefik.http.routers.{{ container_name }}-http.entrypoints={{ traefik_entrypoint }}
      {% if traefik_tls_enabled %}
      - traefik.http.routers.{{ container_name }}-https.service={{ container_name }}
      - traefik.http.routers.{{ container_name }}-https.rule=Host(`{{ traefik_host }}`)
      - traefik.http.routers.{{ container_name }}-https.entrypoints={{ traefik_tls_entrypoint }}
      - traefik.http.routers.{{ container_name }}-https.tls=true
      - traefik.http.routers.{{ container_name }}-https.tls.certresolver={{ traefik_tls_certresolver }}
      {% endif %}
  {% if registry_enabled %}
      - traefik.http.services.{{ container_name }}-registry.loadbalancer.server.port={{ ports_registry }}
      - traefik.http.services.{{ container_name }}-registry.loadbalancer.server.scheme=http
      - traefik.http.routers.{{ container_name }}-registry-http.service={{ container_name }}-registry
      - traefik.http.routers.{{ container_name }}-registry-http.rule=Host(`{{ traefik_registry_host }}`)
      - traefik.http.routers.{{ container_name }}-registry-http.entrypoints={{ traefik_entrypoint }}
      {% if traefik_tls_enabled %}
      - traefik.http.routers.{{ container_name }}-registry-https.service={{ container_name }}-registry
      - traefik.http.routers.{{ container_name }}-registry-https.rule=Host(`{{ traefik_registry_host }}`)
      - traefik.http.routers.{{ container_name }}-registry-https.entrypoints={{ traefik_tls_entrypoint }}
      - traefik.http.routers.{{ container_name }}-registry-https.tls=true
      - traefik.http.routers.{{ container_name }}-registry-https.tls.certresolver={{ traefik_tls_certresolver }}
      {% endif %}
  {% endif %}
{% endif %}
    restart: {{ restart_policy }}

volumes:
  gitlab-config:
    driver: local
  gitlab-logs:
    driver: local
  gitlab-data:
    driver: local

{% if traefik_enabled %}
networks:
  {{ traefik_network }}:
    external: true
{% endif %}
